//
//  WBNetWorkTools.swift
//  Swift中网络请求的封装
//
//  Created by 风不会停息 on 2016/11/14.
//  Copyright © 2016年 风不会停息. All rights reserved.
//

import UIKit

import AFNetworking

enum HttpMethod:Int {
    case GET = 0
    case POST
}

class WBNetWorkTools: AFHTTPSessionManager {
    
    
    static let tool:WBNetWorkTools = {
       
        let tool = WBNetWorkTools()
//        tool.responseSerializer.acceptableContentTypes?.insert("text/html")
        tool.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
        return tool
    }()
    
    
    func request(method:HttpMethod,urlString:String,parameter:Any?,finished:@escaping (Any?,Error?)->())
    {
        if method == .GET {
            self.get(urlString, parameters: parameter, progress: nil, success: { (_, responseObject) in
                finished(responseObject, nil)
            }, failure: { (_, error) in
                finished(nil, error)
            })
        }
        if method == .POST {
            self.post(urlString, parameters: parameter, progress: nil, success: { (_, responseObject) in
                finished(responseObject, nil)
            }, failure: { (_, error) in
                finished(nil, error)
            })
        }
    }
    

}
